<?php
/**
 * Created by PhpStorm.
 * User: asus
 * Date: 2017/10/9
 * Time: 15:37
 */

namespace Wechat\Controller;
use Common\Controller\AdminbaseController;

class XinzhuanController extends AdminbaseController
{
    //批量删除
    public function delall()
    {
        $post = i('post.');
        if(IS_POST) {
            foreach ($post['ids'] as $k) {
                M($post['biao'])->where(['id' => $k])->delete();
            }
            $this->redirect(U($post['url']));
        }
    }
    //删除
    public function del()
    {
        $id = i('get.id');
        if(M(i('get.biao'))->where(['id'=>$id])->delete()){
            $this->success('删除成功!~');
        }else{
            $this->error('失败，未知错误');
        }
    }
    //修改排序
    public function edit()
    {
        $id = i('get.id');
        $biao = i('get.biao');
        $url = i('get.url');
        if(IS_POST){
            $post = i('post.');
            if(M($biao)->where(['id'=>$id])->save(['sort'=>$post['sort']])){
                $this->success('修改成功!~',U($url));
            }else{
                $this->error('失败，未知错误');
            }
        }else{
            $data = M($biao)->where(['id'=>$id])->find();
            $this->assign('vo',$data);
            $this->display();
        }
    }
    //添加浏览量
    public function add2()
    {
        $id = i('get.id');
        $biao = i('get.biao');
        $data = M($biao)->where(['id'=>$id])->find();
        $read = $data['read']+1;
        $return = ['read'=>$read,'status'=>1,'id'=>$id];
        if(M($biao)->where(['id'=>$id])->save(['read'=>$read])){
            echo json_encode($return);
        }else{
            echo 2;
        }
    }
    //租赁转介
    public function zulin()
    {
        $count      = M('zhuanzulin')->order('id desc')->count();
        $Page       = new \Think\Page($count,20);
        $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show       = $Page->show();
        $list = M('zhuanzulin')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign(['page'=>$show,'data'=>$list]);
        $this->display();
    }
    //二手房转介 build 出售1  求买2
    public function ershou()
    {
        $count      = M('zhuanershou')->order('id desc')->count();
        $Page       = new \Think\Page($count,20);
        $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show       = $Page->show();
        $list = M('zhuanershou')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign(['page'=>$show,'data'=>$list]);
        $this->display();
    }
    //新房转介
    public function xinfang()
    {
        $count      = M('zhuanxinfang')->order('id desc')->count();
        $Page       = new \Think\Page($count,20);
        $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show       = $Page->show();
        $list = M('zhuanxinfang')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign(['page'=>$show,'data'=>$list]);
        $this->display();
    }
    //其他转介 type 1 装修 2 搬家
    public function qita()
    {
        $count      = M('zhuanqita')->order('id desc')->count();
        $Page       = new \Think\Page($count,20);
        $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show       = $Page->show();
        $list = M('zhuanqita')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign(['page'=>$show,'data'=>$list]);
        $this->display();
    }
    //项目转介 build 1 是团队 2是项目
    public function xiangmu()
    {
        $count      = M('zhuanxiangmu')->order('id desc')->count();
        $Page       = new \Think\Page($count,20);
        $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show       = $Page->show();
        $list = M('zhuanxiangmu')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign(['page'=>$show,'data'=>$list]);
        $this->display();
    }
    //单位招聘
    public function danwei()
    {
        $count      = M('zhuandanwei')->order('id desc')->count();
        $Page       = new \Think\Page($count,20);
        $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show       = $Page->show();
        $list = M('zhuandanwei')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign(['page'=>$show,'data'=>$list]);
        $this->display();
    }
}